﻿using System;
using System.Collections.Generic;
using System.Data.Entity.Core;
using System.Linq;
using System.Reflection;
using System.Web;
using System.Web.Mvc;
using CustomMVCFilterDemo.Filters;

namespace CustomMVCFilterDemo.Controllers
{
    [CustomExceptionFilter]
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult About()
        {
            try
            {
                throw new EntitySqlException("Throwing SQL Exception from About()");
                ViewData["Message"] = "Your application description page.";
            }
            catch (Exception e)
            {
                var csf = new CustomExceptionFilter();//  'This is needed only to access WriteLog()
                var ec = new ExceptionContext();
                var MethodName = MethodBase.GetCurrentMethod().Name;

                csf.WriteLog(String.Format("Logging MethodName={0}; Exception Message={1}", MethodName, e.Message));

                throw e;//Ex  'This is required to ensure OnException gets called.
            }
            return View();
        }

        public ActionResult Contact()
        {
            int a, b, c;
            a = 3;
            b = 0;
            c = (a / b);//  'this intended to throw an OVERFLOW exception

            ViewData["Message"] = "Your contact page.";


            return View();
        }
    }
}